package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"qq_service/find_qun_by_word/protobuf/pb"
	"strings"
)

//两个服务器，收到关键字，查询QQqunlist,写入队列
var Addresses = []string{"127.0.0.1:9002"}
var i int = 0

func ServerMsg(msg string) {
	//"计算机,软件工程#yincheng01@163.com"
	msglist := strings.Split(msg, "#")
	wordstr := msglist[0]
	wordlist := strings.Split(wordstr, ",")

	//轮流
	conn, err := grpc.Dial(Addresses[i%len(Addresses)], grpc.WithInsecure())
	if err != nil {
		fmt.Println(err)
	}
	defer conn.Close()

	c := pb.NewFindQunByWordServiceClient(conn)
	req := &pb.QqRequest{Word: wordlist, Email: msglist[1]}
	res, err := c.FindQunByWord(context.Background(), req)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("收到", len(res.Qun))
	for i := 0; i < len(res.Qun); i++ {
		fmt.Println(res.Qun[i])
	}

	i++
}
func main() {
	rr := NewReceivedRabbitMQ("amqp://admin:admin@192.168.56.103:5672/", "FindQunByWord_task_queue")
	rr.ReceiveData(ServerMsg)
}

//517894224
